//
//  LSBeginViewController.swift
//  niceapp-ios
//
//  Created by sujeking on 2017/8/1.
//  Copyright © 2017年 szw. All rights reserved.
//

import UIKit

class LSBeginViewController: UIViewController {
    
    @IBOutlet weak var logoImageView: UIImageView!
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        
        let time = DispatchTime.now() + .seconds(3)
        DispatchQueue.main.asyncAfter(deadline: time) {
            self.push()
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.push()
    }
    
    func push() {
        let sb = UIStoryboard.init(name: "Main", bundle: nil)
        let vc = sb.instantiateViewController(withIdentifier: "LSLoginViewController") as! LSLoginViewController
        
        self.navigationController?.wxs_pushViewController(vc, makeTransition: { (wxs) in
            wxs?.animationType = LSTransitionAnimationType.brickOpenVertical
            wxs?.animationTime = 0.5
        })
    }
    
    // MARK: - Init
    
    func setupUI() {
        addYellowLine()
        addTingLine()
        addGreenLine()
        addYellowBoal()
        addTinRedBoal()
        addTingBoal()
        
        self.navigationController?.navigationBar.isHidden = true;
    }
    
    func addYellowLine() {
        let path = UIBezierPath()
        let layer = CAShapeLayer()
        
        path.move(to: CGPoint(x: 0, y: kHeight - 30))
        path.addQuadCurve(to: CGPoint(x: kWidth / 2, y: kHeight),
                          controlPoint: CGPoint(x: kWidth / 4, y: kHeight - 100))
        path.addLine(to: CGPoint(x: 0, y: kHeight))
        path.close()
        
        layer.path = path.cgPath
        layer.fillColor = #colorLiteral(red: 1, green: 0.5781051517, blue: 0, alpha: 1).cgColor
        
        self.view.layer.addSublayer(layer)
    }
    
    func addTingLine() {
        let path = UIBezierPath()
        let layer = CAShapeLayer()
        
        path.move(to: CGPoint(x: 0, y: kHeight - 50))
        path.addCurve(to: CGPoint(x: kWidth, y: kHeight - 100),
                      controlPoint1: CGPoint(x: kWidth / 3, y: kHeight + 50),
                      controlPoint2: CGPoint(x: kWidth / 3 + 50, y: kHeight - 50))
        
        path.addLine(to: CGPoint(x: kWidth, y: kHeight))
        path.addLine(to: CGPoint(x: 0, y: kHeight))
        path.close()
        
        layer.path = path.cgPath
        layer.fillColor = #colorLiteral(red: 0.003921568627, green: 0.831372549, blue: 0.5882352941, alpha: 0.6).cgColor
        
        self.view.layer.addSublayer(layer)
    }
    
    func addGreenLine() {
        let path = UIBezierPath()
        let layer = CAShapeLayer()
        
        path.move(to: CGPoint(x: 0, y: kHeight))
        path.addQuadCurve(to: CGPoint(x: kWidth, y: kHeight),
                          controlPoint: CGPoint(x: kWidth / 2, y: kHeight - 100))
        path.close()
        
        layer.path = path.cgPath
        layer.fillColor = #colorLiteral(red: 0, green: 0.8078431373, blue: 0.7333333333, alpha: 0.5).cgColor
        
        self.view.layer.addSublayer(layer)
    }
    
    func addYellowBoal() {
        let path = UIBezierPath()
        let layer = CAShapeLayer()
        
        path.addArc(withCenter: CGPoint(x: kWidth / 4 - 20, y: kHeight - 100),
                    radius: 8,
                    startAngle: 0,
                    endAngle: CGFloat(2 * M_PI),
                    clockwise: true)
        
        layer.path = path.cgPath
        layer.fillColor = #colorLiteral(red: 1, green: 0.5781051517, blue: 0, alpha: 1).cgColor
        
        self.view.layer.addSublayer(layer)
    }
    
    func addTinRedBoal() {
        let path = UIBezierPath()
        let layer = CAShapeLayer()
        
        path.addArc(withCenter: CGPoint(x: kWidth - 30, y: kHeight - 130),
                    radius: 10,
                    startAngle: 0,
                    endAngle: CGFloat(2 * M_PI),
                    clockwise: true)
        
        layer.path = path.cgPath
        layer.fillColor = #colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1).cgColor
        
        self.view.layer.addSublayer(layer)
    }
    
    func addTingBoal() {
        let path = UIBezierPath()
        let layer = CAShapeLayer()
        
        path.addArc(withCenter: CGPoint(x: kWidth * 3 / 4, y: kHeight - 100),
                    radius: 6,
                    startAngle: 0,
                    endAngle: CGFloat(2 * M_PI),
                    clockwise: true)
        
        layer.path = path.cgPath
        layer.fillColor = #colorLiteral(red: 0.003921568627, green: 0.831372549, blue: 0.5882352941, alpha: 1).cgColor
        
        self.view.layer.addSublayer(layer)
    }
}
